package guava.study.lyh.other;

import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者 yaohua.liu
 * 时间 2014-07-21 11:03
 * 包名 com.qunar.fresh.lyh
 * 说明 ...
 */
public class Guava_2_2_新集合类型 {
    Logger logger = LoggerFactory.getLogger(Guava_2_2_新集合类型.class);

    @Test
    public void testMultimap() {
        Multimap<String, String> multimap = HashMultimap.create();
        multimap.putAll("test", getParam());
        multimap.putAll("a", getParam());
        multimap.put("a", "a");
        multimap.put("b11", "b");

        Preconditions.checkArgument(7== multimap.size());
        Preconditions.checkArgument(3==multimap.get("test").size());
        Preconditions.checkArgument(3== multimap.get("a").size());
        System.out.println(multimap.get("a"));

        Multimap<String, String> arrayListMultiMap = ArrayListMultimap.create();
        arrayListMultiMap.putAll("test", getParam());
        /*java.util.Map<String, java.util.Collection<String>> map = Multimaps.asMap(arrayListMultiMap);
        System.out.println(map.size()+":"+map);
        Preconditions.checkArgument(3== map.get("test").size());*/

    }

    private List<String> getParam() {
        List<String> list = new ArrayList();
        list.add("cc");
        list.add("a");
        list.add("b");
        return list;
    }

}
